<template>
	<AbnormalTemplate :treeData="treeData" @treeHandle="treeHandle">
		<div slot="rightBtn">&nbsp;<el-button @click="downloadExcel">导出</el-button></div>
		<Table
			:tableData="tableData"
			:tableHead="tableHead"
			:propKey="{ prop: 'id', label: 'name' }"
			:isUseSlot="false"
			:page="listQuery.page"
			:limit="listQuery.limit"
			v-loading="listLoading"
			@handleEdit="handleEdit"
		>
		</Table>

		<Pagination
			v-show="total > 0"
			:total="total"
			:page.sync="listQuery.page"
			:limit.sync="listQuery.limit"
			@pagination="getList"
		></Pagination>
	</AbnormalTemplate>
</template>
<script>
import AbnormalTemplate from "@/template/abnormal.temp.vue";
import Table from "@/components/Table";
import Pagination from "@/components/Pagination"; // 分页
import { getSupervisionTableList } from "@/api/RCIM/RCIM-nuclearSafetyRanking";
import {
	ExportExcelSupervision
} from "@/api/RCIM/RCIM-downloadFile";
import moment from "moment";
export default {
	name: "KdHistoryData",
	components: { AbnormalTemplate, Table, Pagination },
	data() {
		return {
			treeData: {},
			total: 5,
			listLoading: true,
			listQuery: {
				page: 1,
				limit: 10,
				nodeId: "",
				startTime: "",
				endTime: ""
				// importance: undefined,
				// title: undefined,
				// type: undefined,
				// sort: '+id'
			},
			showDetail: false,
			tableData: [],
			tableHead: [
				{
					id: "enterprise",
					name: "企业",
					width: ""
				},
				{
					id: "legalPerson",
					name: "法人",
					align: "center",
					width: ""
				},
				{
					id: "sourceCode",
					name: "源国家编码",
					align: "center",
					width: ""
				},
				{
					id: "abnormalType",
					name: "异常类型",
					align: "center",
					width: ""
				},
				{
					id: "chargeDepartment",
					name: "分管单位",
					align: "center",
					width: ""
				},
				{
					id: "abnormalTime",
					name: "异常时间",
					align: "center",
					width: ""
				},
				{
					id: "abnormalTotalTime",
					name: "异常总时长",
					align: "center",
					width: ""
				},
				{
					id: "operate",
					name: "操作",
					align: "center",
					width: ""
				}
			]
		};
	},
	mounted() {

	},
	created() {
		// this.getList();
	},
	methods: {
		/**
		 * @desc 导出表格
		 */
		downloadExcel(){
			this.$confirm('确认要导出为Excel吗？')
				.then(_ => {
					this.donloadLoading = true;
					this.getExcel({
						callback: ExportExcelSupervision,
						params: this.listQuery,
						id: 'abnormalSupervision'
					}).then(res => {
						this.donloadLoading = false;
					}).catch(err => {
						this.donloadLoading = false;
					})
				})
				.catch(_ => {});
		},
		/**
		 * @desc 点击表格详情按钮函数
		 * @param {Object} row 表格行数据
		 */
		handleEdit(row) {
			console.log(row);
			this.$router.push({
				path: "/RCIM-abnormalHandle",
				query: { id: row.id }
			});
		},
		/**
		 * @desc 点击左侧树回调
		 * @param {Object} param 树节点数据
		 */
		treeHandle(param) {
			console.log(param);
			this.listQuery.nodeId = param.id;
			this.listQuery.nodeType = param.type;
			this.listQuery.startTime = moment(param.startTime).format(
				"YYYY-MM-DD"
			);
			this.listQuery.endTime = moment(param.endTime).format("YYYY-MM-DD");
			this.listQuery.treeType = param.treeType;
			this.getList();
		},
		/**
		 * @desc 获取表格数据
		 */
		async getList() {
			this.listLoading = true;
			const { data } = await getSupervisionTableList(this.listQuery);
			this.total = data.total;
			this.tableData = data.supervisionTableList;
			sessionStorage.setItem(
				"abnormalList",
				JSON.stringify(this.tableData)
			);
			this.listLoading = false;
		}
	}
};
</script>

<style lang="scss" scoped></style>
